package May._06.test33;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

public class Main {
    public static void main(String[] args) {
        ArrayList<Product> products = new ArrayList<>();
        ArrayList<Order> orders = new ArrayList<>();
        ArrayList<Product> allProducts = new ArrayList<>();
        Iterator<Order> iterator = orders.iterator();
        while (iterator.hasNext()){
            Order next = iterator.next();
            Product[] singleOrderProducts = next.orderMsg(products);
            for (Product singleOrderProduct : singleOrderProducts) {
                if (singleOrderProduct!=null){
                    allProducts.add(singleOrderProduct);
                }
            }
        }
        allProducts.forEach(new Consumer<Product>() {
            @Override
            public void accept(Product product) {
                System.out.println(product);
            }
        });

    }
}
@Data
@AllArgsConstructor
@NoArgsConstructor
class Product{
    int id;//0表示不存在
    String name;
    double price;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
class Order{
    int id;
    int[] productIds;
    double orderPrice;
    public Product[] orderMsg(ArrayList<Product> products){
        Product[] singleOrderProducts = new Product[productIds.length];
        int index=0;
        for (int i = 0; i < productIds.length; i++) {
            if (productIds[i]!=0){
                Iterator<Product> iterator = products.iterator();
                while (iterator.hasNext()){
                    Product next = iterator.next();
                    if(next.id==productIds[i]){
                        singleOrderProducts[index]=next;
                    }
                }
            }
        }
        return singleOrderProducts;
    }
}
